import { createRouter, createWebHashHistory } from 'vue-router'
import type { RouterTypes } from '~/basic'
import Layout from '@/layout/index.vue'

export const constantRoutes: RouterTypes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404.vue'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401.vue'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
  },
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard/home',
    alwaysShow: true,
    meta: { title: '管理面板', icon: 'manage' },
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/dashboard/home.vue'),
        meta: { title: '主页', icon: 'home' }
      },
      {
        path: 'overview',
        name: 'Equipment',
        component: () => import('@/views/dashboard/overview.vue'),
        meta: { title: '资产总览', icon: 'equipment' }
      }, {
        path: 'purchase',
        name: 'Purchase',
        component: () => import('@/views/dashboard/purchase.vue'),
        meta: {
          title: '采购申请',
          icon: 'buy'
        }
      }
    ]
  },
  // {
  //   path: '/statistic',
  //   component: Layout,
  //   redirect: '/statistic/radar-map',
  //   alwaysShow: true,
  //   meta: { title: '数据分析', icon: 'statistic' },
  //   children: [
  //     {
  //       path: 'radar-map',
  //       name: 'YearCake',
  //       component: () => import('@/views/statistic/radar-map.vue'),
  //       meta: { title: '雷达图', icon: 'cake' }
  //     },
  //     {
  //       path: 'month-bar',
  //       name: 'MonthBar',
  //       component: () => import('@/views/statistic/month-bar.vue'),
  //       meta: { title: '月度柱状图', icon: 'bar' }
  //     }
  //   ]
  // },
  { path: "/:pathMatch(.*)", redirect: "/404", hidden: true }
]

//角色和code数组动态路由
export const roleCodeRoutes: RouterTypes = [

]
/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes: RouterTypes = [
  // 404 page must be placed at the end !!!
]

const router = createRouter({
  history: createWebHashHistory(),
  scrollBehavior: () => ({ top: 0 }),
  routes: constantRoutes
})

export default router
